﻿Public Class FSelectContract

    Private mResult As Generic.List(Of Entities.Backup.ReceivedContract)

    Public Shadows Function ShowDialog(ByVal owner As IWin32Window, ByVal hideContracts As Generic.List(Of Entities.Backup.ReceivedContract)) As Generic.List(Of Entities.Backup.ReceivedContract)
        Dim aContracts As Generic.List(Of Entities.Backup.ReceivedContract)
        aContracts = EntityHandlers.Backup.ReceivedContracts.GetAll
        For Each clsContract As Entities.Backup.ReceivedContract In aContracts
            Dim blnInclude As Boolean = True
            For Each clsTmp As Entities.Backup.ReceivedContract In hideContracts
                If clsTmp.Id = clsContract.Id Then
                    blnInclude = False
                    Exit For
                End If
            Next
            If blnInclude Then
                Dim clsBuddy As Entities.Buddy
                clsBuddy = Framework.Buddies.Manager.GetById(clsContract.IssuedByBuddyId)
                With lvwContracts.Items.Add(clsBuddy.NameLocal)
                    .SubItems.Add(Framework.Misc.ToReadableFileSize(clsContract.StorageSize))
                    .SubItems.Add(clsContract.Comment)
                    .Tag = clsContract
                End With
            End If
        Next
        MyBase.ShowDialog(owner)
        Return mResult
    End Function


    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Try
            Dim aTmp As New Generic.List(Of Entities.Backup.ReceivedContract)
            For Each clsItem As ListViewItem In lvwContracts.SelectedItems
                aTmp.Add(CType(clsItem.Tag, Entities.Backup.ReceivedContract))
            Next
            mResult = aTmp
            Me.Close()
        Catch ex As Exception
            Framework.Misc.HandleException(Me, ex)
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class